<template>
<div class="admin-log-container">
  <!--查询条件-->
  <el-form :inline="true" :model="formInline" class="center-form-inline">
    <el-form-item label="操作人">
      <el-input v-model="formInline.usernameSearch" placeholder="操作人"></el-input>
    </el-form-item>
    <el-form-item label="记录日期">
      <el-date-picker
        v-model="datePick"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd"
        @change="handleDatePick">
      </el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="fetchData">查询</el-button>
    </el-form-item>
  </el-form>
  <!--列表-->
  <el-table style="width: 100%;margin: 10px auto"
            :data="tableData"
            v-loading.body="tableLoading"
            element-loading-text="加载中"
            border fit highlight-current-row>
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column prop="logId" label="日志编号"></el-table-column>
    <el-table-column prop="uname" label="操作人"></el-table-column>
    <el-table-column prop="rname" label="角色"></el-table-column>
    <el-table-column prop="deptName" label="所在单位"></el-table-column>
    <el-table-column prop="recordTime" label="操作时间"></el-table-column>
    <el-table-column prop="operate" label="操作内容">
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-tooltip content="删除" placement="top">
          <el-button @click="handleDelete(scope.$index,scope.row)" size="mini" type="danger">删除</el-button>
        </el-tooltip>
      </template>
    </el-table-column>
  </el-table>
  <div style="margin-bottom: 30px;"></div>
  <!--分页-->
  <el-pagination
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
    :current-page="tablePage.current"
    :page-sizes="[10, 20, 30, 40, 50]"
    :page-size="tablePage.size"
    layout="total, sizes, prev, pager, next, jumper"
    :total="tablePage.total">
  </el-pagination>
  </div>
</template>

<script>
    import logApi from '@/api/log'

    export default {
    name: 'admin_log',
      data() {
          return {
              tableLoading: false,
              tableData: [{

              }],
              tablePage: {
                  current: 1,
                  pages: 0,
                  size: 10,
                  total: 0
              },
              formInline: {
                  usernameSearch:'',
                  recordTimeSearchStart:'',
                  recordTimeSearchEnd:''
              },
              datePick:null,
          }
      },
      created: function() {
          this.fetchData()
      },
      methods: {
          handleClick(tab, event) {
              console.log(tab, event);
          },
          //分页
          handleSizeChange(val) {
              this.tablePage.size = val;
              this.fetchData();
          },
          handleCurrentChange(val) {
              this.tablePage.current = val;
              this.fetchData();
          },
          //查询
          fetchData() {
              this.tableLoading = true
              logApi.getAdminLog(this.formInline, this.tablePage).then(res => {
                  this.tableData = res.data.page.records
                  this.tableLoading = false
                  this.tablePage.current = res.data.page.current;
                  this.tablePage.size = res.data.page.size;
                  this.tablePage.total = res.data.page.total;
              })
          },
          handleDelete(idx, row){
              this.$confirm('您确定要永久删除该日志？', '提示', confirm).then(() => {
                  logApi.deleteLog({logId: row.logId}).then(res => {
                      this.tableData.splice(idx, 1)
                      --this.tablePage.total
                      //this.dialogFormVisible = false
                      this.$message.success("删除成功")
                  })
              }).catch(res => {
                  console.log(res)
                  this.$message.info("已取消删除")
              });
          },
          //日期处理
          handleDatePick(val) {
            this.formInline.recordTimeSearchStart = val[0];
            this.formInline.recordTimeSearchEnd = val[1];
          }
      }
  }
</script>

<style scoped>
  .admin-log-container >>> .el-tabs__content{
    display: none;
  }
  .center-form-inline {
    padding: 20px 10px 0;
    justify-content: center;
  }
</style>

